package com.stoken.web.control;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stoken.domain.MemberActiveList;
import com.stoken.domain.MemberBaseInfo;
import com.stoken.domain.MemberRegisterInfo;
import com.stoken.domain.MemberWallet;
import com.stoken.service.MemberAchievementService;
import com.stoken.service.MemberActiveListService;
import com.stoken.service.MemberBaseInfoService;
import com.stoken.service.MemberRegisterInfoService;
import com.stoken.service.MemberWalletService;
import com.stoken.service.impl.StokenRule;
import com.stoken.web.StokenUtils;
import com.stoken.web.control.vo.AchievementVo;
import com.stoken.web.control.vo.Message;
import com.stoken.web.control.vo.Register;
import com.symbio.utils.EncryptUtils;

@Controller
@RequestMapping("/memberBI")
public class MemberBaseInfoControl {
	
	@Autowired
	private MemberBaseInfoService memberBaseInfoService;
	
	@Autowired
	private MemberRegisterInfoService memberRegisterInfoService;
	
	@Autowired
	private MemberWalletService memberWalletService;
	
	@Autowired
	private MemberActiveListService memberActiveListService;
	
	@Autowired
	private MemberAchievementService memberAchievementService;		
	
	
	/**
	 * 用户注册界面
	 */
	@RequestMapping("/registerIndex")
	public String registerIndex(HttpServletRequest request,Register register){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		request.setAttribute("mbi", mbi);
        return "member/register";
	}
	
	/**
	 * 用户注册界面
	 */
	@RequestMapping("/registerAdd")
	public void registerAdd(HttpServletRequest request,HttpServletResponse reponse,Register register){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
	
		String parentUsername = register.getParentUsername();
		int location = new Integer(register.getLocation());
		//查看是否合法
		 Message message = memberRegisterInfoService.isLegalforRegister(register.getCommendUsername(),parentUsername,location);
		if(message.getCode() == 0)
		{
			print(reponse,message);
			return ;
		}
		
		String hql = "from MemberRegisterInfo where baseUsername = ?";
		MemberRegisterInfo reg = memberRegisterInfoService.findRegisterByParentUserName(hql , parentUsername);
		//销售人员
		MemberBaseInfo rBaseInfo = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?",register.getCommendUsername());
		//服务人员对象
		MemberBaseInfo fBaseInfo = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?",reg.getBaseUsername());
		String level = reg.getRegisterLevel();
		String[] uLevels = level.split("-");
		int[] uls = new int[]{new Integer(uLevels[0]),new Integer(uLevels[1])};
		
		
		MemberRegisterInfo registerInfo = new MemberRegisterInfo();
		//用户登录的名字
		registerInfo.setBaseUsername(register.getUsername());
		//服务人员
		registerInfo.setParentUsername(fBaseInfo);
		//销售人员
		registerInfo.setRegisterCommendUsername(rBaseInfo);
		//位置
		registerInfo.setRegisterLocation(register.getLocation());
		//注册级别
		registerInfo.setRegisterGrade(0);
		//是否激活
		registerInfo.setRegisterAvtivestate(0);
		//注册层次
		if(register.getLocation()==0)
		{
			registerInfo.setRegisterLevel((uls[0]+1)+"-"+(2*uls[1]-1));
		}
		else
		{
			registerInfo.setRegisterLevel((uls[0]+1)+"-"+(2*uls[1]));
		}

		MemberBaseInfo baseInfo = new MemberBaseInfo();
		//用户登录的名字
		baseInfo.setBaseUsername(register.getUsername());
		//身份证姓名
		baseInfo.setBaseName(register.getName());
		//身份证卡号
		baseInfo.setBaseIdcard(register.getIdcard());
		//一级密码
		baseInfo.setBasePasswordFirst(EncryptUtils.md5(register.getPwd()));
		//二级密码
		baseInfo.setBasePasswordSeconde(EncryptUtils.md5(register.getIdcard().length()>=6?register.getIdcard().substring(register.getIdcard().length()-6):register.getPwd()));
		//三级密码
		baseInfo.setBasePasswordThird(EncryptUtils.md5(register.getIdcard().length()>=6?register.getIdcard().substring(register.getIdcard().length()-6):register.getPwd()));
		//第一次注册时间
		baseInfo.setBaseFirstregisterTime(new Date());
		
		memberBaseInfoService.saveRegisterInfo(registerInfo,baseInfo);
		
		print(reponse,new Message(1,""));
	}
	
	/**
	 * 查询服务人员列表
	 */
	@RequestMapping("/serverList")
	public String serverList(HttpServletRequest request,HttpServletResponse reponse,String username,String level){
		List<MemberRegisterInfo> regList = memberBaseInfoService.findServerList(username,level);
		request.setAttribute("regList", regList);
		return "member/registerList";
	}
	
	/**
	 * 用户名的验证
	 */
	@RequestMapping("/isCheckUsername")
	public void isCheckUsername(HttpServletResponse reponse, String username){
		MemberBaseInfo baseInfo = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?",username);
		PrintWriter out = null;
		try {
			out = reponse.getWriter();
			out.print(baseInfo == null);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			out.close();
		}
	}
	
	/**
	 * 验证推荐人员是否存在
	 */
	@RequestMapping("/isCheckCUsername")
	public void isCheckCUsername(HttpServletResponse reponse, String cUsername){
		MemberBaseInfo mbi = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?",cUsername);
	    boolean boo = false;
		if(mbi != null)
	    {
	    	boo = true;
	    }
		PrintWriter out = null;
		try {
			out = reponse.getWriter();
			out.print(boo);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			out.close();
		}
	}
	
	
	/**
	 * 查询用户基本信息
	 */
	@RequestMapping("/index")
	public String index(HttpServletRequest request,String mid){
        return "";
	}
	
	/**
	 * 查询用户基本信息
	 */
	@RequestMapping("/findMBI")
	public String findMBI(HttpServletRequest request,String mid){
		
		memberBaseInfoService.find(new Long(mid));
        return "";
	}
	
	/**
	 * 更新用户基本信息
	 */
	@RequestMapping("/updateMBI")
	public String updateMBI(HttpServletRequest request,MemberBaseInfo mbi){
		memberBaseInfoService.updateMBI(mbi);
		return "";
	}
	
	/**
	 * 绑定手机号码
	 */
	@RequestMapping("/bingPhone")
	public String bingPhone(HttpServletRequest request,String phone,String validationCode,String mid)
	{
		//如果验证码正确
		if(!StringUtils.equalsIgnoreCase("123", validationCode))
		{
			return "";
		}
		memberBaseInfoService.updatePhone(phone,new Long(mid));
		return "";
	}
	
	/**
	 * 发送手机验证码
	 */
	@RequestMapping("/sendPhoneCode")
	public void sendPhoneCode(HttpServletRequest request,String phone){
		//发送手机验证码
		request.getSession().setAttribute("phoneCode", "123");
	}
	
    /**会员激活*/
	
	/**
	 * 激活会员界面
	 */
	@RequestMapping("/activeMemberIndex")
	public String activeMemberIndex(HttpServletRequest request,String tPassword){
		//获得session里面的user信息
		MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		MemberWallet memberWallet = memberWalletService.findWalletByUsername(mbi.getBaseUsername());
		List<MemberActiveList> activeList = memberActiveListService.findActiveListByUsername(mbi.getBaseUsername());
		request.setAttribute("memberWallet", memberWallet);
		request.setAttribute("activeList", activeList);
		return "member/activationmember";
	}
	
	/**
	 * 激活会员
	 */
	@RequestMapping("/activeMember")
	public void activeMember(HttpServletRequest request,HttpServletResponse reponse,String activeName,String grade){
		if((0 == StokenRule.getHourNow())){
			 print(reponse,new Message(0,"上午0点到1点为系统奖金核算，关闭激活"));
		}
    	//获得session里面的user信息
		MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		Message message = memberBaseInfoService.updateActiveMember(mbi.getBaseUsername(),activeName,grade);
	    print(reponse,message);
	}
	
	/**
	 * 查看需要激活的会员是否合法
	 */
	@RequestMapping("/checkActiveMember")
	public void checkActiveMember(HttpServletResponse reponse,String activeName){
		//MemberBaseInfo mbi = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?", activeName);
		MemberRegisterInfo registerInfo = memberRegisterInfoService.findRegisterByUserName(activeName);
		boolean boo = false;
		if(registerInfo!=null && registerInfo.getRegisterAvtivestate()==0)
	    {
			boo = true;
	    }
		PrintWriter out = null;
		try {
			out = reponse.getWriter();
			out.print(boo);
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			out.close();
		}
		
	}
	
	/**
	 * 输出
	 * @param response
	 * @param message
	 */
	private void print(HttpServletResponse response,Message message){
		try {
			String json = "{\"code\":\""+message.getCode()+"\",\"context\":\""+message.getContext()+"\"}";  
			response.setContentType("text/html;charset=UTF-8");
			PrintWriter out = response.getWriter();
			out.write(json);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**我的文档*/
	
	
	/**
	 * 我的文档
	 */
	@RequestMapping("/myprofile")
	public String activeMember(HttpServletRequest request){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		mbi = memberBaseInfoService.get(mbi.getId());
		request.setAttribute("mbi", mbi);
		return "operat/myprofile";
	}
	
	/**
	 * 修改手机号码界面
	 */
	@RequestMapping("/phoneIndex")
	public String phoneIndex(HttpServletRequest request){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		request.setAttribute("mbi", mbi);
		return "operat/changeTel";
	}
	
	/**
	 * 修改手机号码界面
	 */
	@RequestMapping("/updatePhone")
	public String updatePhone(HttpServletRequest request,String phone){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		mbi = memberBaseInfoService.get(mbi.getId());
		mbi.setBasePhone(phone);
		memberBaseInfoService.update(mbi);
		request.setAttribute("mbi", mbi);
		request.getSession().setAttribute(StokenUtils.LOGINACCOUNT, mbi);
		return "operat/myprofile";
	}
	
	/**
	 * 修改邮箱界面
	 */
	@RequestMapping("/emailIndex")
	public String emailIndex(HttpServletRequest request){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		request.setAttribute("mbi", mbi);
		return "operat/changeEmail";
	}
	
	/**
	 * 修改邮箱
	 */
	@RequestMapping("/updateEmail")
	public String updateEmail(HttpServletRequest request,String email){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		mbi = memberBaseInfoService.get(mbi.getId());
		mbi.setBaseEmailMain(email);
		memberBaseInfoService.update(mbi);
		request.setAttribute("mbi", mbi);
		request.getSession().setAttribute(StokenUtils.LOGINACCOUNT, mbi);
		return "operat/myprofile";
	}
	
	/**
	 * 修改银行界面
	 */
	@RequestMapping("/bankIndex")
	public String bankIndex(HttpServletRequest request){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		request.setAttribute("mbi", mbi);
		return "operat/changeBank";
	}
	
	/**
	 * 修改银行
	 */
	@RequestMapping("/updateBank")
	public String updateBank(HttpServletRequest request,String bankName,String subbranch,String account){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		mbi = memberBaseInfoService.get(mbi.getId());
		mbi.setBaseBankname(bankName);
		mbi.setBaseSubbranch(subbranch);
		mbi.setBaseAccount(account);
		memberBaseInfoService.update(mbi);
		request.getSession().setAttribute(StokenUtils.LOGINACCOUNT, mbi);
		request.setAttribute("mbi", mbi);
		return "operat/myprofile";
	}
	
	/**
	 * 查看银行
	 */
	@RequestMapping("/findBankInfo")
	public String findBankInfo(HttpServletRequest request){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		request.setAttribute("mbi", mbi);
		return "operat/lookBank";
	}
	
	/**
	 * 查看二级密码是否正确
	 * @param request
	 * @param sPassword
	 */
	public boolean findSecondP(HttpServletRequest request,String sPassword){
		//获得session里面的user信息
		MemberBaseInfo mbInfo = (MemberBaseInfo)request.getSession().getAttribute("user");
		return memberBaseInfoService.findSercondP(mbInfo.getId(),EncryptUtils.md5(sPassword));
	}
	
	/**
	 * 更新密码首页
	 */
	@RequestMapping("/pwdIndex")
	public String pwdIndex(HttpServletRequest request,String type){
		if(StringUtils.equals(type, "1")){
			request.setAttribute("num", "一");
		}else if(StringUtils.equals(type, "2")){
			request.setAttribute("num", "二");
		}else if(StringUtils.equals(type, "3")){
			request.setAttribute("num", "三");
		}
		request.setAttribute("type", type);
		return "operat/changePassword";
	}
	
	/**
	 * 更新密码
	 */
	@RequestMapping("/updatePassword")
	public String updateFP(HttpServletRequest request,String type,String pwd,String newPwd){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		mbi = memberBaseInfoService.get(mbi.getId());
		if(StringUtils.equals(type, "1"))
		{
			memberBaseInfoService.updateFPassword(mbi.getId(),EncryptUtils.md5(newPwd));	
		}
		else if(StringUtils.equals(type, "2"))
		{
			memberBaseInfoService.updateSPassword(mbi.getId(),EncryptUtils.md5(newPwd));
		}
		else if(StringUtils.equals(type, "3"))
		{
			memberBaseInfoService.updateTPassword(mbi.getId(),EncryptUtils.md5(newPwd));
		}
		request.setAttribute("mbi", mbi);
		request.getSession().setAttribute(StokenUtils.LOGINACCOUNT, mbi);
	    return "operat/myprofile";
	}
	
	/**
	 * 查看密码
	 */
	@RequestMapping("/lookPassword")
	public void lookPassword(HttpServletRequest request,HttpServletResponse response,String type,String password){
		MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		mbi = memberBaseInfoService.get(mbi.getId());
		boolean boo = false;
		PrintWriter out  = null;
		try {
			out = response.getWriter();		
		if(StringUtils.equals(type, "1") && StringUtils.equals(mbi.getBasePasswordFirst(), EncryptUtils.md5(password)))
		{
			boo = true;
		}
		if(StringUtils.equals(type, "2") && StringUtils.equals(mbi.getBasePasswordSeconde(), EncryptUtils.md5(password)))
		{
			boo = true;
		}
		if(StringUtils.equals(type, "3") && StringUtils.equals(mbi.getBasePasswordThird(), EncryptUtils.md5(password)))
		{
			boo = true;
		}
		out.print(boo);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			out.close();
		}
	}
	
	/**申请升级*/
	
	/**
	 * 申请升级首页
	 * @param request
	 * @param response
	 * @param type
	 * @param password
	 */
	@RequestMapping("/applyUpgradeIndex")
	public String applyUpgradeIndex(HttpServletRequest request,HttpServletResponse response){
		MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		MemberWallet memberWallet = memberWalletService.findWalletByUsername(mbi.getBaseUsername());
		MemberRegisterInfo registerInfo = memberRegisterInfoService.findRegisterByUserName(mbi.getBaseUsername());
		request.setAttribute("mbi", mbi);
		request.setAttribute("memberWallet", memberWallet);
		request.setAttribute("registerInfo", registerInfo);
		return "member/applyupgrade";
	}
	
	/**
	 * 申请升级
	 */
	@RequestMapping("/applyUpgrade")
	public void applyUpgrade(HttpServletRequest request ,HttpServletResponse response,String grade){
		MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		MemberWallet memberWallet = memberWalletService.findWalletByUsername(mbi.getBaseUsername());
		MemberRegisterInfo registerInfo = memberRegisterInfoService.findRegisterByUserName(mbi.getBaseUsername());
		if(StringUtils.isNotBlank(grade))
		{
			if(registerInfo.getRegisterGrade() >= new Integer(grade))
			{
				print(response,new Message(0,"请选择更高的加盟级别"));
			}
		}else
		{
			print(response,new Message(0,"请选择加盟级别"));
		}
		
		if(memberWallet == null)
		{
			print(response,new Message(0,"电子钱包为空"));
		}

		double registerMoney = StokenUtils.COPPERMONEY;
		//**
		if(StringUtils.equals(grade, "1"))
		{
			registerMoney = StokenUtils.COPPERMONEY;
		}
		else if(StringUtils.equals(grade, "2"))
		{
			registerMoney = StokenUtils.SILVERMONEY;
		}
		else if(StringUtils.equals(grade, "5"))
		{
			registerMoney = StokenUtils.GOLDENMONEY;
		}
		else if(StringUtils.equals(grade, "10"))
		{
			registerMoney = StokenUtils.VIPMONEY;
		}
		else if(StringUtils.equals(grade, "30"))
		{
			registerMoney = StokenUtils.MASONRYMONEY;
		}
		
		double money = memberWallet.getWalletRemain();
		if(money - registerMoney < 0)
		{
			print(response,new Message(0,"电子钱包余额不足"));
		}
		
		//激活注册状态
		registerInfo.setRegisterGrade(new Integer(grade));
		registerInfo.setRegisterActivetime(new Date());
		registerInfo.setRegisterAvtivestate(1);
		memberRegisterInfoService.update(registerInfo);
		
		//减少电子钱包金额
		memberWallet.setWalletRemain(memberWallet.getWalletRemain()-registerMoney);
		memberWalletService.update(memberWallet);
		
		
		//添加电子钱包明细
		MemberActiveList entity = new MemberActiveList();
		entity.setActiveName(mbi.getBaseName());
		entity.setActiveTime(new Date());
		entity.setActiveType(new Integer(grade));
		entity.setActiveUsername(registerInfo.getBaseUsername());
		entity.setBaseUsername(mbi);
		entity.setWalletRemain(memberWallet.getWalletRemain()-registerMoney);
		memberActiveListService.save(entity);
		
		request.getSession().setAttribute(StokenUtils.REGISTERGRADE, grade);
		
		print(response, new Message(1,""));
		
	}
	
	/**销售人员信息*/
	
	/**
	 * 销售人员界面
	 * @return
	 */
	@RequestMapping("/saleIndex")
	public String saleIndex(){
		return "member/salespersonnel";
	}
	
	@RequestMapping("/saleList")
	public String saleList(HttpServletRequest request,HttpServletResponse response,String pageNo){
		int page = 1;
		if(StringUtils.isNotBlank(pageNo))
		{
			page = new Integer(pageNo);
		}
		MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		List list = memberAchievementService.findAchievement(mbi.getBaseUsername(),page);
		int max = list.size();
		int count = StokenUtils.pageSize;
		int start = (page-1) * count;
		List aList = null ;
		List<AchievementVo> achList = new ArrayList<AchievementVo>();
		if(list != null && list.size()>0)
		{
			if(max<start){
				aList = list.subList(max-count, max);
			}else{
				aList = list.subList(start, start+count>=max?max:start+count);
			}
			for (int i = 0; i < aList.size(); i++) {
				Object[] obj = (Object[]) aList.get(i);
				AchievementVo aVo = new AchievementVo(); 
				aVo.setBaseUsername(obj[0].toString());
				aVo.setBaseName(obj[1].toString());
				aVo.setRegisterGrade(new Integer(obj[2].toString()));
				aVo.setAchievementLeftNew(new Integer(obj[3].toString()));
				aVo.setAchievementRightNew(new Integer(obj[4].toString()));
				aVo.setAchievementLeftTotal(new Integer(obj[5].toString()));
				aVo.setAchievementRightTotal(new Integer(obj[6].toString()));
				achList.add(aVo);
			}
		    Pagination p = new Pagination();
			p.setIntTotalNum(max);
			p.setCurpage(page);
			p.setPagenum(count);
			request.setAttribute("pagination", p.showPages());
			request.setAttribute("achList", achList);
		}

		
		return "member/salePage";
	}
	
	/**部门信息*/
	@RequestMapping("/sectorIndex")
	public String sectorIndex(HttpServletRequest request){
		MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
       
		List list = memberAchievementService.findAchievementByPUsername(mbi.getId());
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			AchievementVo aVo = new AchievementVo(); 
			aVo.setBaseUsername(obj[0].toString());
			aVo.setBaseName(obj[1].toString());
			aVo.setRegisterGrade(new Integer(obj[2].toString()));
			aVo.setAchievementLeftNew(new Integer(obj[3].toString()));
			aVo.setAchievementRightNew(new Integer(obj[4].toString()));
			aVo.setAchievementLeftTotal(new Integer(obj[5].toString()));
			aVo.setAchievementRightTotal(new Integer(obj[6].toString()));
			
			if(new Integer(obj[7].toString())==0)
			{
				request.setAttribute("location0", aVo);
			}
			if(new Integer(obj[7].toString())==1)
			{
				request.setAttribute("location1", aVo);
			}
		}

		return "member/sectorinfromation";
	}
	
	@RequestMapping("/deleteAccount")
	public void  deleteAccount(String account,HttpServletResponse response){
		MemberRegisterInfo memberRegister = memberRegisterInfoService.findRegisterByParentUserName("", account);
		if(memberRegister != null){
			memberRegisterInfoService.delete(memberRegister);
		}
		MemberBaseInfo memberBase = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?", account);
		if(memberBase != null){
			memberBaseInfoService.delete(memberBase);
		}
		print(response, new Message(1,"删除未激活会员成功"));
		
	}
	
	/**
	 * 检查待激活的账号
	 * @param account
	 * @param response
	 */
	@RequestMapping("/checkUserAccount")
	@ResponseBody
	public String  checkUserAccount(String activeName,HttpServletResponse response){		
		MemberRegisterInfo register = memberRegisterInfoService.findRegisterByUserName(activeName);
		if(register==null)
		{
			return "待激活会员不存在";
		}
		if(register.getRegisterAvtivestate()==1)
		{
			return "会员已激活";
		}
		MemberBaseInfo baseInfo = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?", activeName);
		return "待激活会员姓名："+baseInfo.getBaseName();
	}
	
	/**
	 * 初始化会员密码
	 * @param baseAccount
	 * @return
	 */
	@RequestMapping("/backstage/initMBIPsw")
    public void initMBIPsw(String baseAccount,String baseName,String initPsw,HttpServletResponse response){		
	    if(StringUtils.isEmpty(baseAccount)){
	    	print(response,new Message(0,"用户名不能够为空"));
	    	return;
	    }
		MemberBaseInfo baseInfo = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?", baseAccount);
		if(baseInfo == null){
			print(response,new Message(0,"用户名不存在"));
			return;
		}
		if(StringUtils.isEmpty(baseName)){
			print(response,new Message(0,"用户名不能够为空"));
			return;
		}
		
		if(StringUtils.equals(initPsw, "true")){  //初始化用户名密码
			String pwd = baseInfo.getBaseIdcard().substring(baseInfo.getBaseIdcard().length()-6);
			baseInfo.setBasePasswordFirst(EncryptUtils.md5(pwd));
			baseInfo.setBasePasswordSeconde(EncryptUtils.md5(pwd));
			baseInfo.setBasePasswordThird(EncryptUtils.md5(pwd));
			
		}
		memberBaseInfoService.save(baseInfo);
		print(response,new Message(0,"修改信息成功"));
	}
	
	@RequestMapping("/backstage/loadInitMBIPsw")
    public String loadMBIPswPage(String baseAccount,ModelMap modelMap){
		if(StringUtils.isNotBlank(baseAccount)){
			MemberBaseInfo baseInfo = memberBaseInfoService.findBaseByUserName("from MemberBaseInfo where baseUsername = ?", baseAccount);
			modelMap.addAttribute("memberBaseInfo", baseInfo);
			if(baseInfo == null){
				modelMap.addAttribute("error","用户名不存在");  
			}			
			return "/backstage/memberManage/initPsw";   	
	    }	
		return "/backstage/memberManage/initPsw";    	
    }
	
	
	
	
	
	
}
